infer T extends ..
(extends右項の中で)extendsの左項でもinferが使える
例
code:ts
type FirstIfString<T> =
T extends [infer S extends string, ...unknown[]]
? S
: never;
以下と同じ意味
code:ts
type FirstIfString<T> =
T extends [infer S, ...unknown[]]
? S extends string ? S : never
: never;
code:ts
type FirstIfString<T> =
T extends [string, ...unknown[]] ? T0 : never;